using System;

namespace LFramework
{
    public class FrameTimer : TimerBase
    {
        private int m_TotalFrame;
        private Action m_FinishCB;

        private int m_CurFrame;

        public static FrameTimer Create(int id, int total_frame, Action finish_cb)
        {
            FrameTimer frameTimer = GameEntry.Pool.ClassObjectPool.Dequeue<FrameTimer>();
            frameTimer.Init(id, total_frame, finish_cb);
            return frameTimer;
        }

        public void Init(int id, int total_frame, Action finish_cb)
        {
            ID = id;
            m_TotalFrame = total_frame;
            m_FinishCB = finish_cb;
            m_CurFrame = 0;
        }

        public override void Update(float dt)
        {
            m_CurFrame++;
            if (m_CurFrame >= m_TotalFrame)
            {
                m_FinishCB?.Invoke();
                IsFinished = true;
            }
        }

        public override void Restart()
        {
            m_TotalFrame = 0;
        }
    }
}
